home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Add-Ons / MPW / MPW noweb 2.7 / examples / tree.nw < prev    next >
LaTeX Document  |  1995-05-30  |  11.6 KB  |  [TEXT/MPS ]

open in: MacOS 8.1     |     Win98     |     DOS

browse contents    |     view JSON data     |     view as text


This file was processed as: LaTeX Document (document/latex).

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert LaTeX Document (document/latex) magic Supported
1% dexvert NWiper Show (other/nWiperShow) ext Unsupported
1% dexvert Text File (text/txt) fallback Supported
100% file LaTeX document, ASCII text, with CR line terminators default
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/281 LaTeX (Subdocument) default
100% detectItEasy Format: plain text[CR] default (weak)


id metadata
keyvalue
macFileType[TEXT]
macFileCreator[MPS ]



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 5c 73 65 63 74 69 6f 6e | 7b 47 65 6e 65 72 61 74 |\section|{Generat|
|00000010| 69 6e 67 20 64 65 63 69 | 73 69 6f 6e 20 74 72 65 |ing deci|sion tre|
|00000020| 65 73 7d 0d 0d 54 68 65 | 20 63 72 75 78 20 6f 66 |es}..The| crux of|
|00000030| 20 74 68 65 20 70 72 6f | 62 6c 65 6d 20 69 73 20 | the pro|blem is |
|00000040| 74 6f 20 74 72 61 6e 73 | 66 6f 72 6d 20 61 20 7b |to trans|form a {|
|00000050| 5c 65 6d 20 63 61 73 65 | 20 73 74 61 74 65 6d 65 |\em case| stateme|
|00000060| 6e 74 7d 20 69 6e 74 6f | 20 61 0d 7b 5c 65 6d 20 |nt} into| a.{\em |
|00000070| 64 65 63 69 73 69 6f 6e | 20 74 72 65 65 7d 2e 20 |decision| tree}. |
|00000080| 20 41 20 63 61 73 65 20 | 73 74 61 74 65 6d 65 6e | A case |statemen|
|00000090| 74 20 68 61 73 20 61 20 | 7b 5c 65 6d 20 76 61 6c |t has a |{\em val|
|000000a0| 75 65 7d 2c 20 61 20 73 | 65 71 75 65 6e 63 65 0d |ue}, a s|equence.|
|000000b0| 6f 66 20 7b 5c 65 6d 20 | 61 72 6d 73 7d 2c 20 61 |of {\em |arms}, a|
|000000c0| 6e 64 20 61 20 7b 5c 65 | 6d 20 74 72 61 69 6c 65 |nd a {\e|m traile|
|000000d0| 72 7d 2e 0d 45 61 63 68 | 20 61 72 6d 20 68 61 73 |r}..Each| arm has|
|000000e0| 20 61 20 70 61 74 74 65 | 72 6e 2c 20 61 6e 64 20 | a patte|rn, and |
|000000f0| 63 6f 64 65 20 74 6f 20 | 62 65 20 65 78 65 63 75 |code to |be execu|
|00000100| 74 65 64 2e 0d 57 68 65 | 6e 20 74 68 65 20 63 61 |ted..Whe|n the ca|
|00000110| 73 65 20 73 74 61 74 65 | 6d 65 6e 74 20 69 73 20 |se state|ment is |
|00000120| 65 78 65 63 75 74 65 64 | 2c 20 69 74 20 63 68 6f |executed|, it cho|
|00000130| 6f 73 65 73 20 74 68 65 | 20 66 69 72 73 74 20 61 |oses the| first a|
|00000140| 72 6d 20 77 68 6f 73 65 | 0d 70 61 74 74 65 72 6e |rm whose|.pattern|
|00000150| 20 6d 61 74 63 68 65 73 | 20 74 68 65 20 76 61 6c | matches| the val|
|00000160| 75 65 2c 20 74 68 65 6e | 20 65 78 65 63 75 74 65 |ue, then| execute|
|00000170| 73 20 74 68 65 20 63 6f | 72 72 65 73 70 6f 6e 64 |s the co|rrespond|
|00000180| 69 6e 67 20 63 6f 64 65 | 2c 20 74 68 65 6e 0d 65 |ing code|, then.e|
|00000190| 78 65 63 75 74 65 73 20 | 74 68 65 20 74 72 61 69 |xecutes |the trai|
|000001a0| 6c 65 72 2e 0d 49 20 67 | 65 6e 65 72 61 74 65 20 |ler..I g|enerate |
|000001b0| 61 20 7b 5c 65 6d 20 64 | 65 63 69 73 69 6f 6e 20 |a {\em d|ecision |
|000001c0| 74 72 65 65 7d 20 74 6f | 20 64 6f 20 74 68 65 20 |tree} to| do the |
|000001d0| 6a 6f 62 2e 0d 45 61 63 | 68 20 69 6e 74 65 72 6e |job..Eac|h intern|
|000001e0| 61 6c 20 6e 6f 64 65 20 | 6f 66 20 74 68 65 20 64 |al node |of the d|
|000001f0| 65 63 69 73 69 6f 6e 20 | 74 72 65 65 20 74 65 73 |ecision |tree tes|
|00000200| 74 73 20 61 20 66 69 65 | 6c 64 20 6f 66 20 74 68 |ts a fie|ld of th|
|00000210| 65 20 76 61 6c 75 65 2e | 0d 49 74 20 74 68 65 6e |e value.|.It then|
|00000220| 20 63 68 6f 6f 73 65 73 | 20 61 6e 20 65 64 67 65 | chooses| an edge|
|00000230| 20 28 63 68 69 6c 64 29 | 20 62 61 73 65 64 20 6f | (child)| based o|
|00000240| 6e 20 74 68 61 74 20 76 | 61 6c 75 65 2c 20 61 6e |n that v|alue, an|
|00000250| 64 20 63 6f 6e 74 69 6e | 75 65 73 0d 74 65 73 74 |d contin|ues.test|
|00000260| 69 6e 67 20 66 69 65 6c | 64 73 20 75 6e 74 69 6c |ing fiel|ds until|
|00000270| 20 69 74 20 72 65 61 63 | 68 65 73 20 61 20 6c 65 | it reac|hes a le|
|00000280| 61 66 2c 20 61 74 20 77 | 68 69 63 68 20 74 69 6d |af, at w|hich tim|
|00000290| 65 20 69 74 20 65 78 65 | 63 75 74 65 73 20 74 68 |e it exe|cutes th|
|000002a0| 65 0d 63 6f 64 65 20 61 | 73 73 6f 63 69 61 74 65 |e.code a|ssociate|
|000002b0| 64 20 77 69 74 68 20 74 | 68 61 74 20 6c 65 61 66 |d with t|hat leaf|
|000002c0| 2e 0d 0d 54 68 65 20 67 | 6f 61 6c 20 6f 66 20 74 |...The g|oal of t|
|000002d0| 72 65 65 20 67 65 6e 65 | 72 61 74 69 6f 6e 20 69 |ree gene|ration i|
|000002e0| 73 20 6e 6f 74 20 74 6f | 20 67 65 6e 65 72 61 74 |s not to| generat|
|000002f0| 65 20 6a 75 73 74 20 61 | 6e 79 20 74 72 65 65 2c |e just a|ny tree,|
|00000300| 20 62 75 74 20 74 68 65 | 0d 74 72 65 65 20 77 69 | but the|.tree wi|
|00000310| 74 68 20 74 68 65 20 66 | 65 77 65 73 74 20 6e 6f |th the f|ewest no|
|00000320| 64 65 73 2e 20 20 54 68 | 69 73 20 70 72 6f 62 6c |des. Th|is probl|
|00000330| 65 6d 20 69 73 20 4e 50 | 2d 63 6f 6d 70 6c 65 74 |em is NP|-complet|
|00000340| 65 2c 20 73 6f 20 49 20 | 61 70 70 6c 79 0d 61 20 |e, so I |apply.a |
|00000350| 66 65 77 20 68 65 75 72 | 69 73 74 69 63 73 2e 20 |few heur|istics. |
|00000360| 20 54 68 65 20 72 65 73 | 75 6c 74 73 2c 20 61 74 | The res|ults, at|
|00000370| 20 6c 65 61 73 74 20 66 | 6f 72 20 74 68 65 20 6d | least f|or the m|
|00000380| 61 63 68 69 6e 65 20 64 | 65 73 63 72 69 70 74 69 |achine d|escripti|
|00000390| 6f 6e 73 0d 49 20 75 73 | 65 2c 20 73 65 65 6d 20 |ons.I us|e, seem |
|000003a0| 74 6f 20 62 65 20 61 73 | 20 67 6f 6f 64 20 61 73 |to be as| good as|
|000003b0| 20 77 68 61 74 20 49 20 | 77 6f 75 6c 64 20 63 6f | what I |would co|
|000003c0| 6d 65 20 75 70 20 77 69 | 74 68 20 62 79 20 68 61 |me up wi|th by ha|
|000003d0| 6e 64 2e 0d 40 0d 54 68 | 65 20 61 72 6d 73 20 6f |nd..@.Th|e arms o|
|000003e0| 66 20 74 68 65 20 63 61 | 73 65 20 73 74 61 74 65 |f the ca|se state|
|000003f0| 6d 65 6e 74 20 68 61 76 | 65 20 73 6f 6d 65 20 65 |ment hav|e some e|
|00000400| 78 74 72 61 20 69 6e 66 | 6f 72 6d 61 74 69 6f 6e |xtra inf|ormation|
|00000410| 2e 0d 54 68 65 20 66 69 | 6c 65 20 61 6e 64 20 6c |..The fi|le and l|
|00000420| 69 6e 65 20 6e 75 6d 62 | 65 72 20 68 65 6c 70 20 |ine numb|er help |
|00000430| 77 69 74 68 20 65 72 72 | 6f 72 20 6d 65 73 73 61 |with err|or messa|
|00000440| 67 65 20 61 6e 64 20 6d | 61 6b 65 20 69 74 20 70 |ge and m|ake it p|
|00000450| 6f 73 73 69 62 6c 65 0d | 74 6f 20 67 65 6e 65 72 |ossible.|to gener|
|00000460| 61 74 65 20 5b 5b 23 6c | 69 6e 65 5d 5d 20 73 74 |ate [[#l|ine]] st|
|00000470| 61 74 65 6d 65 6e 74 73 | 20 74 68 61 74 20 69 64 |atements| that id|
|00000480| 65 6e 74 69 66 79 20 74 | 68 65 20 73 6f 75 72 63 |entify t|he sourc|
|00000490| 65 20 6f 66 20 74 68 65 | 20 63 6f 64 65 2e 0d 54 |e of the| code..T|
|000004a0| 68 65 20 6f 72 69 67 69 | 6e 61 6c 20 61 72 6d 20 |he origi|nal arm |
|000004b0| 67 69 76 65 73 20 74 68 | 65 20 61 72 6d 20 66 72 |gives th|e arm fr|
|000004c0| 6f 6d 20 77 68 69 63 68 | 20 74 68 65 20 63 75 72 |om which| the cur|
|000004d0| 72 65 6e 74 20 61 72 6d | 20 69 73 20 64 65 72 69 |rent arm| is deri|
|000004e0| 76 65 64 2c 0d 61 6e 64 | 20 69 73 20 75 73 65 66 |ved,.and| is usef|
|000004f0| 75 6c 20 66 6f 72 20 6d | 61 6e 79 20 6f 66 20 74 |ul for m|any of t|
|00000500| 68 65 20 68 65 75 72 69 | 73 74 69 63 73 2e 0d 3c |he heuri|stics..<|
|00000510| 3c 2a 3e 3e 3d 0d 72 65 | 63 6f 72 64 20 63 61 73 |<*>>=.re|cord cas|
|00000520| 65 72 65 63 28 61 72 6d | 73 2c 76 61 6c 63 6f 64 |erec(arm|s,valcod|
|00000530| 65 2c 74 72 61 69 6c 65 | 72 29 0d 09 09 23 20 63 |e,traile|r)...# c|
|00000540| 61 73 65 20 61 72 6d 73 | 2c 20 63 6f 64 65 20 74 |ase arms|, code t|
|00000550| 6f 20 63 6f 6d 70 75 74 | 65 20 76 61 6c 75 65 2c |o comput|e value,|
|00000560| 20 74 72 61 69 6c 69 6e | 67 20 63 6f 64 65 0d 72 | trailin|g code.r|
|00000570| 65 63 6f 72 64 20 61 72 | 6d 28 66 69 6c 65 2c 20 |ecord ar|m(file, |
|00000580| 6c 69 6e 65 2c 20 70 61 | 74 74 65 72 6e 2c 20 63 |line, pa|ttern, c|
|00000590| 6f 64 65 2c 20 6f 72 69 | 67 69 6e 61 6c 29 0d 09 |ode, ori|ginal)..|
|000005a0| 09 23 20 70 61 74 74 65 | 72 6e 20 61 6e 64 20 63 |.# patte|rn and c|
|000005b0| 6f 64 65 20 61 72 65 20 | 74 68 65 20 63 6f 6e 74 |ode are |the cont|
|000005c0| 65 6e 74 0d 09 09 23 20 | 6c 69 6e 65 2c 20 66 69 |ent...# |line, fi|
|000005d0| 6c 65 2c 20 6f 72 69 67 | 69 6e 61 6c 28 70 61 74 |le, orig|inal(pat|
|000005e0| 74 65 72 6e 29 20 61 72 | 65 20 75 73 65 64 20 66 |tern) ar|e used f|
|000005f0| 6f 72 20 65 72 72 6f 72 | 20 72 65 70 6f 72 74 69 |or error| reporti|
|00000600| 6e 67 0d 40 0d 45 61 63 | 68 20 6e 6f 64 65 20 6f |ng.@.Eac|h node o|
|00000610| 66 20 74 68 65 20 64 65 | 63 69 73 69 6f 6e 20 74 |f the de|cision t|
|00000620| 72 65 65 20 69 73 20 61 | 73 73 6f 63 69 61 74 65 |ree is a|ssociate|
|00000630| 64 20 77 69 74 68 20 61 | 20 70 61 72 74 69 63 75 |d with a| particu|
|00000640| 6c 61 72 20 63 61 73 65 | 0d 73 74 61 74 65 6d 65 |lar case|.stateme|
|00000650| 6e 74 2e 0d 49 6e 74 65 | 72 6e 61 6c 20 6e 6f 64 |nt..Inte|rnal nod|
|00000660| 65 73 20 68 61 76 65 20 | 63 68 69 6c 64 72 65 6e |es have |children|
|00000670| 2c 20 61 6e 64 20 61 20 | 5b 5b 66 69 65 6c 64 5d |, and a |[[field]|
|00000680| 5d 20 77 68 69 63 68 20 | 73 61 79 73 20 77 68 69 |] which |says whi|
|00000690| 63 68 20 66 69 65 6c 64 | 0d 77 65 20 64 65 63 69 |ch field|.we deci|
|000006a0| 64 65 64 20 74 6f 20 74 | 65 73 74 20 6f 6e 2e 20 |ded to t|est on. |
|000006b0| 20 54 68 65 20 65 64 67 | 65 73 20 74 68 61 74 20 | The edg|es that |
|000006c0| 70 6f 69 6e 74 20 74 6f | 20 74 68 65 20 63 68 69 |point to| the chi|
|000006d0| 6c 64 72 65 6e 20 72 65 | 63 6f 72 64 0d 74 68 65 |ldren re|cord.the|
|000006e0| 20 69 6e 74 65 72 76 61 | 6c 20 6f 66 20 76 61 6c | interva|l of val|
|000006f0| 75 65 73 20 66 6f 72 20 | 74 68 65 20 70 61 72 74 |ues for |the part|
|00000700| 69 63 75 6c 61 72 20 63 | 68 69 6c 64 2e 0d 4c 65 |icular c|hild..Le|
|00000710| 61 66 20 6e 6f 64 65 73 | 20 68 61 76 65 20 61 20 |af nodes| have a |
|00000720| 5b 5b 6e 61 6d 65 5d 5d | 20 74 68 61 74 20 72 65 |[[name]]| that re|
|00000730| 63 6f 72 64 73 20 74 68 | 65 20 6e 61 6d 65 20 6f |cords th|e name o|
|00000740| 66 20 74 68 65 20 70 61 | 74 74 65 72 6e 20 6b 6e |f the pa|ttern kn|
|00000750| 6f 77 6e 0d 74 6f 20 6d | 61 74 63 68 20 61 74 20 |own.to m|atch at |
|00000760| 74 68 61 74 20 6c 65 61 | 66 20 6e 6f 64 65 2e 0d |that lea|f node..|
|00000770| 3c 3c 2a 3e 3e 3d 0d 72 | 65 63 6f 72 64 20 6e 6f |<<*>>=.r|ecord no|
|00000780| 64 65 28 63 73 2c 20 63 | 68 69 6c 64 72 65 6e 2c |de(cs, c|hildren,|
|00000790| 20 66 69 65 6c 64 2c 20 | 6e 61 6d 65 29 0d 09 23 | field, |name)..#|
|000007a0| 20 63 61 73 65 20 73 74 | 61 74 65 6d 65 6e 74 2c | case st|atement,|
|000007b0| 20 6c 69 73 74 20 6f 66 | 20 65 64 67 65 73 20 74 | list of| edges t|
|000007c0| 6f 20 63 68 69 6c 64 72 | 65 6e 2c 20 66 69 65 6c |o childr|en, fiel|
|000007d0| 64 20 63 68 6f 73 65 6e | 2c 20 70 61 74 74 65 72 |d chosen|, patter|
|000007e0| 6e 20 6e 61 6d 65 0d 09 | 23 09 28 6e 61 6d 65 20 |n name..|#.(name |
|000007f0| 66 69 65 6c 64 20 75 73 | 65 64 20 74 6f 20 73 75 |field us|ed to su|
|00000800| 70 70 6f 72 74 20 6e 61 | 6d 65 20 6f 70 65 72 61 |pport na|me opera|
|00000810| 74 6f 72 2c 20 61 73 73 | 69 67 6e 65 64 20 6f 6e |tor, ass|igned on|
|00000820| 6c 79 20 74 6f 20 6c 65 | 61 76 65 73 29 0d 72 65 |ly to le|aves).re|
|00000830| 63 6f 72 64 20 65 64 67 | 65 28 6e 6f 64 65 2c 20 |cord edg|e(node, |
|00000840| 6c 6f 2c 20 68 69 29 0d | 09 23 20 6e 6f 64 65 20 |lo, hi).|.# node |
|00000850| 70 6f 69 6e 74 65 64 20 | 74 6f 20 61 6e 64 20 6c |pointed |to and l|
|00000860| 6f 20 61 6e 64 20 68 69 | 20 69 6e 74 65 72 76 61 |o and hi| interva|
|00000870| 6c 20 6f 66 20 66 69 65 | 6c 64 20 66 6f 72 20 74 |l of fie|ld for t|
|00000880| 68 69 73 20 65 64 67 65 | 0d 40 0d 54 6f 20 63 72 |his edge|.@.To cr|
|00000890| 65 61 74 65 20 61 20 64 | 65 63 69 73 69 6f 6e 20 |eate a d|ecision |
|000008a0| 74 72 65 65 2c 20 49 20 | 62 65 67 69 6e 20 77 69 |tree, I |begin wi|
|000008b0| 74 68 20 61 20 6e 6f 64 | 65 20 63 6f 6e 74 61 69 |th a nod|e contai|
|000008c0| 6e 69 6e 67 20 74 68 65 | 20 66 75 6c 6c 2c 0d 6f |ning the| full,.o|
|000008d0| 72 69 67 69 6e 61 6c 20 | 63 61 73 65 20 73 74 61 |riginal |case sta|
|000008e0| 74 65 6d 65 6e 74 2e 20 | 20 49 20 74 68 65 6e 20 |tement. | I then |
|000008f0| 75 73 65 20 61 20 60 60 | 77 6f 72 6b 20 71 75 65 |use a ``|work que|
|00000900| 75 65 27 27 20 61 70 70 | 72 6f 61 63 68 20 74 6f |ue'' app|roach to|
|00000910| 20 63 68 65 63 6b 0d 65 | 61 63 68 20 6e 6f 64 65 | check.e|ach node|
|00000920| 20 61 6e 64 20 73 65 65 | 20 69 66 20 69 74 20 6e | and see| if it n|
|00000930| 65 65 64 73 20 74 6f 20 | 62 65 20 73 70 6c 69 74 |eeds to |be split|
|00000940| 2e 0d 49 66 20 6e 6f 20 | 70 61 74 74 65 72 6e 20 |..If no |pattern |
|00000950| 6d 61 74 63 68 65 73 20 | 74 68 65 20 6e 6f 64 65 |matches |the node|
|00000960| 2c 20 6f 72 20 69 66 20 | 74 68 65 20 66 69 72 73 |, or if |the firs|
|00000970| 74 20 70 61 74 74 65 72 | 6e 20 61 6c 77 61 79 73 |t patter|n always|
|00000980| 20 6d 61 74 63 68 65 73 | 0d 28 77 69 74 68 20 61 | matches|.(with a|
|00000990| 20 75 6e 69 71 75 65 20 | 6e 61 6d 65 29 2c 20 6e | unique |name), n|
|000009a0| 6f 20 66 75 72 74 68 65 | 72 20 73 70 6c 69 74 74 |o furthe|r splitt|
|000009b0| 69 6e 67 20 6e 65 65 64 | 73 20 74 6f 20 62 65 20 |ing need|s to be |
|000009c0| 64 6f 6e 65 2c 20 61 6e | 64 20 49 0d 61 73 73 69 |done, an|d I.assi|
|000009d0| 67 6e 20 61 20 6e 61 6d | 65 20 74 6f 20 74 68 65 |gn a nam|e to the|
|000009e0| 20 6c 65 61 66 2e 5c 66 | 6f 6f 74 6e 6f 74 65 7b | leaf.\f|ootnote{|
|000009f0| 49 66 20 74 68 65 20 6e | 61 6d 65 20 69 73 6e 27 |If the n|ame isn'|
|00000a00| 74 20 75 73 65 64 2c 20 | 49 20 61 73 73 69 67 6e |t used, |I assign|
|00000a10| 0d 74 68 65 20 6e 61 6d | 65 20 5b 5b 22 2d 75 6e |.the nam|e [["-un|
|00000a20| 75 73 65 64 2d 22 5d 5d | 2c 20 62 65 63 61 75 73 |used-"]]|, becaus|
|00000a30| 65 20 74 68 61 74 20 77 | 69 6c 6c 20 6d 61 6b 65 |e that w|ill make|
|00000a40| 20 69 74 20 65 61 73 69 | 65 72 20 74 6f 20 63 6f | it easi|er to co|
|00000a50| 6d 62 69 6e 65 0d 6e 6f | 64 65 73 20 69 6e 20 74 |mbine.no|des in t|
|00000a60| 68 65 20 64 61 67 67 69 | 6e 67 20 70 68 61 73 65 |he daggi|ng phase|
|00000a70| 2e 7d 0d 4f 74 68 65 72 | 77 69 73 65 2c 20 49 20 |.}.Other|wise, I |
|00000a80| 73 70 6c 69 74 20 74 68 | 65 20 6e 6f 64 65 2e 0d |split th|e node..|
|00000a90| 3c 3c 2a 3e 3e 3d 0d 70 | 72 6f 63 65 64 75 72 65 |<<*>>=.p|rocedure|
|00000aa0| 20 6e 65 65 64 73 5f 73 | 70 6c 69 74 74 69 6e 67 | needs_s|plitting|
|00000ab0| 28 6e 29 0d 20 20 20 20 | 69 66 20 2a 6e 2e 63 73 |(n). |if *n.cs|
|00000ac0| 2e 61 72 6d 73 20 3d 20 | 30 20 74 68 65 6e 20 66 |.arms = |0 then f|
|00000ad0| 61 69 6c 0d 20 20 20 20 | 70 20 3a 3d 20 6e 2e 63 |ail. |p := n.c|
|00000ae0| 73 2e 61 72 6d 73 5b 31 | 5d 2e 70 61 74 74 65 72 |s.arms[1|].patter|
|00000af0| 6e 0d 20 20 20 20 6e 61 | 6d 65 20 3a 3d 20 5c 70 |n. na|me := \p|
|00000b00| 2e 64 69 73 6a 75 6e 63 | 74 73 5b 31 5d 2e 6e 61 |.disjunc|ts[1].na|
|00000b10| 6d 65 20 7c 20 70 2e 6e | 61 6d 65 0d 20 20 20 20 |me | p.n|ame. |
|00000b20| 65 76 65 72 79 20 64 20 | 3a 3d 20 21 70 2e 64 69 |every d |:= !p.di|
|00000b30| 73 6a 75 6e 63 74 73 20 | 64 6f 20 7b 0d 20 20 20 |sjuncts |do {. |
|00000b40| 20 20 20 20 20 6e 20 3a | 3d 20 5c 64 2e 6e 61 6d | n :|= \d.nam|
|00000b50| 65 20 7c 20 70 2e 6e 61 | 6d 65 0d 20 20 20 20 20 |e | p.na|me. |
|00000b60| 20 20 20 69 66 20 6e 20 | 7e 3d 3d 3d 20 6e 61 6d | if n |~=== nam|
|00000b70| 65 20 74 68 65 6e 20 72 | 65 74 75 72 6e 20 20 20 |e then r|eturn |
|00000b80| 23 20 64 69 66 66 65 72 | 65 6e 74 20 6e 61 6d 65 |# differ|ent name|
|00000b90| 73 2c 20 6e 65 65 64 73 | 20 73 70 6c 69 74 74 69 |s, needs| splitti|
|00000ba0| 6e 67 0d 20 20 20 20 20 | 20 20 20 65 6c 73 65 20 |ng. | else |
|00000bb0| 69 66 20 2a 64 2e 63 6f | 6e 73 74 72 61 69 6e 74 |if *d.co|nstraint|
|00000bc0| 73 20 3d 20 30 20 74 68 | 65 6e 20 66 61 69 6c 09 |s = 0 th|en fail.|
|00000bd0| 23 20 61 6c 77 61 79 73 | 20 6d 61 74 63 68 65 73 |# always| matches|
|00000be0| 2c 20 6e 65 65 64 6e 27 | 74 20 73 70 6c 69 74 0d |, needn'|t split.|
|00000bf0| 20 20 20 20 7d 0d 20 20 | 20 20 72 65 74 75 72 6e | }. | return|
|00000c00| 20 09 09 09 23 20 70 61 | 74 74 65 72 6e 20 64 6f | ...# pa|ttern do|
|00000c10| 65 73 6e 27 74 20 61 6c | 77 61 79 73 20 6d 61 74 |esn't al|ways mat|
|00000c20| 63 68 20 2d 3e 20 73 70 | 6c 69 74 0d 65 6e 64 0d |ch -> sp|lit.end.|
|00000c30| 0d 70 72 6f 63 65 64 75 | 72 65 20 74 72 65 65 28 |.procedu|re tree(|
|00000c40| 63 73 29 0d 20 20 20 20 | 73 74 61 74 69 63 20 68 |cs). |static h|
|00000c50| 65 75 72 69 73 74 69 63 | 73 0d 20 20 20 20 69 6e |euristic|s. in|
|00000c60| 69 74 69 61 6c 20 68 65 | 75 72 69 73 74 69 63 73 |itial he|uristics|
|00000c70| 20 3a 3d 20 5b 6c 65 61 | 66 61 72 6d 73 2c 20 63 | := [lea|farms, c|
|00000c80| 68 69 6c 64 61 72 6d 73 | 2c 20 6e 6f 6d 61 74 63 |hildarms|, nomatc|
|00000c90| 68 2c 20 63 68 69 6c 64 | 64 69 73 6a 75 6e 63 74 |h, child|disjunct|
|00000ca0| 73 2c 20 62 72 61 6e 63 | 68 66 61 63 74 6f 72 5d |s, branc|hfactor]|
|00000cb0| 0d 0d 20 20 20 20 72 6f | 6f 74 20 3a 3d 20 6e 6f |.. ro|ot := no|
|00000cc0| 64 65 28 63 73 29 0d 20 | 20 20 20 77 6f 72 6b 20 |de(cs). | work |
|00000cd0| 3a 3d 20 5b 65 64 67 65 | 28 72 6f 6f 74 29 5d 20 |:= [edge|(root)] |
|00000ce0| 20 20 20 20 20 20 20 23 | 20 77 6f 72 6b 20 71 75 | #| work qu|
|00000cf0| 65 75 65 20 6f 66 20 65 | 64 67 65 73 20 28 6e 6f |eue of e|dges (no|
|00000d00| 64 65 73 29 20 74 6f 20 | 62 65 20 65 78 70 61 6e |des) to |be expan|
|00000d10| 64 65 64 0d 20 20 20 20 | 77 68 69 6c 65 20 6e 20 |ded. |while n |
|00000d20| 3a 3d 20 67 65 74 28 77 | 6f 72 6b 29 2e 6e 6f 64 |:= get(w|ork).nod|
|00000d30| 65 20 64 6f 0d 20 20 20 | 20 20 20 20 20 69 66 20 |e do. | if |
|00000d40| 6e 65 65 64 73 5f 73 70 | 6c 69 74 74 69 6e 67 28 |needs_sp|litting(|
|00000d50| 6e 29 20 74 68 65 6e 20 | 7b 0d 20 20 20 20 20 20 |n) then |{. |
|00000d60| 20 20 20 20 20 20 3c 3c | 73 70 6c 69 74 20 6e 6f | <<|split no|
|00000d70| 64 65 20 5b 5b 6e 5d 5d | 20 61 6e 64 20 61 64 64 |de [[n]]| and add|
|00000d80| 20 63 68 69 6c 64 72 65 | 6e 20 74 6f 20 77 6f 72 | childre|n to wor|
|00000d90| 6b 20 71 75 65 75 65 3e | 3e 0d 20 20 20 20 20 20 |k queue>|>. |
|00000da0| 20 20 7d 20 65 6c 73 65 | 20 7b 0d 09 20 20 20 20 | } else| {.. |
|00000db0| 69 66 20 2a 6e 2e 63 73 | 2e 61 72 6d 73 20 3d 20 |if *n.cs|.arms = |
|00000dc0| 30 20 74 68 65 6e 20 0d | 20 20 20 20 20 20 20 20 |0 then .| |
|00000dd0| 20 20 20 20 20 20 20 20 | 6e 2e 6e 61 6d 65 20 3a | |n.name :|
|00000de0| 3d 20 22 2d 4e 4f 4d 41 | 54 43 48 2d 22 0d 20 20 |= "-NOMA|TCH-". |
|00000df0| 20 20 20 20 20 20 20 20 | 20 20 65 6c 73 65 20 69 | | else i|
|00000e00| 66 20 6e 2e 63 73 2e 61 | 72 6d 73 5b 31 5d 2e 63 |f n.cs.a|rms[1].c|
|00000e10| 6f 64 65 20 3f 20 66 69 | 6e 64 5f 69 64 28 22 6e |ode ? fi|nd_id("n|
|00000e20| 61 6d 65 22 29 20 74 68 | 65 6e 20 7b 0d 20 20 20 |ame") th|en {. |
|00000e30| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 70 20 3a | | p :|
|00000e40| 3d 20 6e 2e 63 73 2e 61 | 72 6d 73 5b 31 5d 2e 70 |= n.cs.a|rms[1].p|
|00000e50| 61 74 74 65 72 6e 0d 20 | 20 20 20 20 20 20 20 20 |attern. | |
|00000e60| 20 20 20 20 20 20 20 6e | 2e 6e 61 6d 65 20 3a 3d | n|.name :=|
|00000e70| 20 5c 70 2e 64 69 73 6a | 75 6e 63 74 73 5b 31 5d | \p.disj|uncts[1]|
|00000e80| 2e 6e 61 6d 65 20 7c 20 | 5c 70 2e 6e 61 6d 65 20 |.name | |\p.name |
|00000e90| 7c 20 22 2d 75 6e 6e 61 | 6d 65 64 2d 22 0d 20 20 || "-unna|med-". |
|00000ea0| 20 20 20 20 20 20 20 20 | 20 20 7d 20 65 6c 73 65 | | } else|
|00000eb0| 20 0d 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | . | |
|00000ec0| 20 20 6e 2e 6e 61 6d 65 | 20 3a 3d 20 26 6e 75 6c | n.name| := &nul|
|00000ed0| 6c 0d 09 20 20 20 20 69 | 66 20 5c 6d 61 70 6e 61 |l.. i|f \mapna|
|00000ee0| 6d 65 73 20 74 68 65 6e | 20 6e 2e 6e 61 6d 65 20 |mes then| n.name |
|00000ef0| 3a 3d 20 6d 61 70 28 5c | 6e 2e 6e 61 6d 65 29 0d |:= map(\|n.name).|
|00000f00| 20 20 20 20 20 20 20 7d | 0d 20 20 20 20 72 65 74 | }|. ret|
|00000f10| 75 72 6e 20 72 6f 6f 74 | 0d 65 6e 64 0d 40 0d 53 |urn root|.end.@.S|
|00000f20| 70 6c 69 74 74 69 6e 67 | 20 61 20 6e 6f 64 65 20 |plitting| a node |
|00000f30| 69 6e 76 6f 6c 76 65 73 | 20 63 68 6f 6f 73 69 6e |involves| choosin|
|00000f40| 67 20 61 20 66 69 65 6c | 64 2c 20 66 69 6e 64 69 |g a fiel|d, findi|
|00000f50| 6e 67 20 6f 75 74 20 77 | 68 69 63 68 20 69 6e 74 |ng out w|hich int|
|00000f60| 65 72 76 61 6c 73 0d 6f | 66 20 76 61 6c 75 65 73 |ervals.o|f values|
|00000f70| 20 6f 66 20 74 68 61 74 | 20 66 69 65 6c 64 20 61 | of that| field a|
|00000f80| 72 65 20 69 6e 74 65 72 | 65 73 74 69 6e 67 2c 20 |re inter|esting, |
|00000f90| 61 6e 64 20 63 72 65 61 | 74 69 6e 67 20 61 20 63 |and crea|ting a c|
|00000fa0| 68 69 6c 64 20 6e 6f 64 | 65 20 66 6f 72 0d 65 61 |hild nod|e for.ea|
|00000fb0| 63 68 20 73 75 63 68 20 | 69 6e 74 65 72 76 61 6c |ch such |interval|
|00000fc0| 20 6f 66 20 76 61 6c 75 | 65 73 2e 20 20 54 68 65 | of valu|es. The|
|00000fd0| 20 70 61 74 74 65 72 6e | 73 20 69 6e 20 74 68 65 | pattern|s in the|
|00000fe0| 20 63 61 73 65 20 73 74 | 61 74 65 6d 65 6e 74 20 | case st|atement |
|00000ff0| 6f 66 20 74 68 65 0d 63 | 68 69 6c 64 20 6e 6f 64 |of the.c|hild nod|
|00001000| 65 20 72 65 66 6c 65 63 | 74 20 74 68 65 20 6b 6e |e reflec|t the kn|
|00001010| 6f 77 6c 65 64 67 65 20 | 6f 66 20 74 68 65 20 76 |owledge |of the v|
|00001020| 61 6c 75 65 20 69 6e 74 | 65 72 76 61 6c 20 6f 66 |alue int|erval of|
|00001030| 20 74 68 65 20 74 65 73 | 74 65 64 0d 66 69 65 6c | the tes|ted.fiel|
|00001040| 64 2e 0d 0d 49 20 6d 61 | 6b 65 20 74 68 65 20 64 |d...I ma|ke the d|
|00001050| 65 63 69 73 69 6f 6e 20 | 62 79 20 73 70 6c 69 74 |ecision |by split|
|00001060| 74 69 6e 67 20 74 68 65 | 20 6e 6f 64 65 20 6f 6e |ting the| node on|
|00001070| 20 7b 5c 65 6d 20 65 61 | 63 68 7d 20 66 69 65 6c | {\em ea|ch} fiel|
|00001080| 64 0d 6d 65 6e 74 69 6f | 6e 65 64 20 69 6e 20 74 |d.mentio|ned in t|
|00001090| 68 65 20 63 61 73 65 20 | 73 74 61 74 65 6d 65 6e |he case |statemen|
|000010a0| 74 2e 20 20 49 20 74 68 | 65 6e 20 63 6f 6d 70 75 |t. I th|en compu|
|000010b0| 74 65 20 73 6f 6d 65 20 | 68 65 75 72 69 73 74 69 |te some |heuristi|
|000010c0| 63 0d 66 75 6e 63 74 69 | 6f 6e 73 20 6f 66 20 74 |c.functi|ons of t|
|000010d0| 68 65 20 63 68 69 6c 64 | 72 65 6e 20 66 72 6f 6d |he child|ren from|
|000010e0| 20 65 61 63 68 20 73 70 | 6c 69 74 74 69 6e 67 20 | each sp|litting |
|000010f0| 61 6e 64 20 75 73 65 20 | 74 68 65 0d 62 65 73 74 |and use |the.best|
|00001100| 2d 73 63 6f 72 69 6e 67 | 20 66 69 65 6c 64 2e 0d |-scoring| field..|
|00001110| 0d 53 6f 6d 65 20 64 65 | 62 75 67 67 69 6e 67 20 |.Some de|bugging |
|00001120| 69 6e 66 6f 72 6d 61 74 | 69 6f 6e 20 6d 61 79 20 |informat|ion may |
|00001130| 62 65 20 77 72 69 74 74 | 65 6e 20 74 6f 20 5b 5b |be writt|en to [[|
|00001140| 68 64 65 62 75 67 5d 5d | 20 6f 72 20 5b 5b 73 64 |hdebug]]| or [[sd|
|00001150| 65 62 75 67 5d 5d 2e 0d | 3c 3c 73 70 6c 69 74 20 |ebug]]..|<<split |
|00001160| 6e 6f 64 65 20 5b 5b 6e | 5d 5d 20 61 6e 64 20 61 |node [[n|]] and a|
|00001170| 64 64 20 63 68 69 6c 64 | 72 65 6e 20 74 6f 20 77 |dd child|ren to w|
|00001180| 6f 72 6b 20 71 75 65 75 | 65 3e 3e 3d 0d 66 69 65 |ork queu|e>>=.fie|
|00001190| 6c 64 73 20 3a 3d 20 6d | 65 6e 74 69 6f 6e 73 28 |lds := m|entions(|
|000011a0| 6e 2e 63 73 29 0d 2a 66 | 69 65 6c 64 73 20 3e 20 |n.cs).*f|ields > |
|000011b0| 30 20 7c 20 69 6d 70 6f | 73 73 69 62 6c 65 28 22 |0 | impo|ssible("|
|000011c0| 69 6e 74 65 72 6e 61 6c | 20 6e 6f 64 65 20 6d 65 |internal| node me|
|000011d0| 6e 74 69 6f 6e 73 20 6e | 6f 20 66 69 65 6c 64 73 |ntions n|o fields|
|000011e0| 22 29 0d 63 61 6e 64 69 | 64 61 74 65 73 20 3a 3d |").candi|dates :=|
|000011f0| 20 74 61 62 6c 65 28 29 | 0d 65 76 65 72 79 20 66 | table()|.every f|
|00001200| 20 3a 3d 20 21 66 69 65 | 6c 64 73 20 64 6f 0d 20 | := !fie|lds do. |
|00001210| 20 20 20 63 61 6e 64 69 | 64 61 74 65 73 5b 66 5d | candi|dates[f]|
|00001220| 20 3a 3d 20 73 70 6c 69 | 74 28 6e 2c 20 66 29 0d | := spli|t(n, f).|
|00001230| 3c 3c 69 66 20 64 65 62 | 75 67 67 69 6e 67 2c 20 |<<if deb|ugging, |
|00001240| 73 70 6c 69 74 20 61 6c | 6c 20 61 6e 64 20 72 65 |split al|l and re|
|00001250| 70 6f 72 74 3e 3e 0d 2a | 66 69 65 6c 64 73 20 3e |port>>.*|fields >|
|00001260| 20 31 20 26 20 77 72 69 | 74 65 28 5c 68 64 65 62 | 1 & wri|te(\hdeb|
|00001270| 75 67 2c 20 22 43 68 6f | 6f 73 69 6e 67 20 6f 6e |ug, "Cho|osing on|
|00001280| 65 20 6f 66 20 22 2c 20 | 70 61 74 69 6d 61 67 65 |e of ", |patimage|
|00001290| 28 66 69 65 6c 64 73 29 | 29 0d 65 76 65 72 79 20 |(fields)|).every |
|000012a0| 68 20 3a 3d 20 21 68 65 | 75 72 69 73 74 69 63 73 |h := !he|uristics|
|000012b0| 20 64 6f 20 7b 0d 20 20 | 20 20 69 66 20 2a 66 69 | do {. | if *fi|
|000012c0| 65 6c 64 73 20 3d 20 31 | 20 74 68 65 6e 20 62 72 |elds = 1| then br|
|000012d0| 65 61 6b 0d 20 20 20 20 | 66 69 65 6c 64 73 20 3a |eak. |fields :|
|000012e0| 3d 20 66 69 6e 64 6d 61 | 78 69 6d 61 28 68 2c 20 |= findma|xima(h, |
|000012f0| 63 61 6e 64 69 64 61 74 | 65 73 2c 20 66 69 65 6c |candidat|es, fiel|
|00001300| 64 73 29 0d 77 72 69 74 | 65 28 5c 68 64 65 62 75 |ds).writ|e(\hdebu|
|00001310| 67 2c 20 69 6d 61 67 65 | 28 68 29 2c 20 22 20 63 |g, image|(h), " c|
|00001320| 68 6f 73 65 20 22 2c 20 | 70 61 74 69 6d 61 67 65 |hose ", |patimage|
|00001330| 28 66 69 65 6c 64 73 29 | 29 0d 7d 0d 2a 66 69 65 |(fields)|).}.*fie|
|00001340| 6c 64 73 20 3e 20 30 20 | 7c 20 69 6d 70 6f 73 73 |lds > 0 || imposs|
|00001350| 69 62 6c 65 28 22 6e 6f | 20 66 69 65 6c 64 73 22 |ible("no| fields"|
|00001360| 29 0d 2a 66 69 65 6c 64 | 73 20 3d 20 31 20 7c 20 |).*field|s = 1 | |
|00001370| 77 72 69 74 65 28 5c 68 | 64 65 62 75 67 2c 20 22 |write(\h|debug, "|
|00001380| 74 69 65 20 61 6d 6f 6e | 67 20 66 69 65 6c 64 73 |tie amon|g fields|
|00001390| 22 2c 20 70 61 74 69 6d | 61 67 65 28 66 69 65 6c |", patim|age(fiel|
|000013a0| 64 73 29 2c 20 22 20 6e | 65 61 72 20 22 2c 0d 20 |ds), " n|ear ",. |
|000013b0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|000013c0| 20 20 20 20 20 69 6d 61 | 67 65 28 6e 2e 63 73 2e | ima|ge(n.cs.|
|000013d0| 61 72 6d 73 5b 31 5d 2e | 6f 72 69 67 69 6e 61 6c |arms[1].|original|
|000013e0| 2e 66 69 6c 65 29 2c 20 | 22 2c 20 6c 69 6e 65 20 |.file), |", line |
|000013f0| 22 2c 0d 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |",. | |
|00001400| 20 20 20 20 20 20 20 20 | 20 6e 2e 63 73 2e 61 72 | | n.cs.ar|
|00001410| 6d 73 5b 31 5d 2e 6f 72 | 69 67 69 6e 61 6c 2e 6c |ms[1].or|iginal.l|
|00001420| 69 6e 65 29 0d 77 6f 72 | 6b 20 7c 7c 7c 3a 3d 20 |ine).wor|k |||:= |
|00001430| 6e 2e 63 68 69 6c 64 72 | 65 6e 20 3a 3d 20 63 61 |n.childr|en := ca|
|00001440| 6e 64 69 64 61 74 65 73 | 5b 6e 2e 66 69 65 6c 64 |ndidates|[n.field|
|00001450| 20 3a 3d 20 3f 66 69 65 | 6c 64 73 5d 0d 3c 3c 69 | := ?fie|lds].<<i|
|00001460| 66 20 64 65 62 75 67 67 | 69 6e 67 2c 20 73 70 6c |f debugg|ing, spl|
|00001470| 69 74 20 61 6c 6c 20 61 | 6e 64 20 72 65 70 6f 72 |it all a|nd repor|
|00001480| 74 3e 3e 3d 0d 69 66 20 | 5c 74 72 79 61 6c 6c 20 |t>>=.if |\tryall |
|00001490| 26 20 5c 68 64 65 62 75 | 67 20 26 20 2a 66 69 65 |& \hdebu|g & *fie|
|000014a0| 6c 64 73 20 3e 20 31 20 | 74 68 65 6e 20 20 20 20 |lds > 1 |then |
|000014b0| 20 7b 0d 20 20 77 72 69 | 74 65 28 5c 68 64 65 62 | {. wri|te(\hdeb|
|000014c0| 75 67 2c 20 72 65 70 6c | 28 22 3d 22 2c 31 30 29 |ug, repl|("=",10)|
|000014d0| 2c 20 22 20 53 70 6c 69 | 74 74 69 6e 67 20 22 2c |, " Spli|tting ",|
|000014e0| 20 72 65 70 6c 28 22 3d | 22 2c 20 31 30 29 29 0d | repl("=|", 10)).|
|000014f0| 20 20 65 76 65 72 79 20 | 66 69 6e 64 6d 61 78 69 | every |findmaxi|
|00001500| 6d 61 28 21 68 65 75 72 | 69 73 74 69 63 73 2c 20 |ma(!heur|istics, |
|00001510| 63 61 6e 64 69 64 61 74 | 65 73 2c 20 66 69 65 6c |candidat|es, fiel|
|00001520| 64 73 29 20 64 6f 20 77 | 72 69 74 65 28 5c 68 64 |ds) do w|rite(\hd|
|00001530| 65 62 75 67 29 0d 20 20 | 77 72 69 74 65 28 5c 68 |ebug). |write(\h|
|00001540| 64 65 62 75 67 2c 20 72 | 65 70 6c 28 22 3d 22 2c |debug, r|epl("=",|
|00001550| 20 33 30 29 2c 20 22 5c | 6e 22 29 0d 7d 0d 40 0d | 30), "\|n").}.@.|
|00001560| 54 6f 20 73 70 6c 69 74 | 20 61 20 6e 6f 64 65 2c |To split| a node,|
|00001570| 20 49 20 6c 6f 6f 6b 20 | 61 74 20 65 61 63 68 20 | I look |at each |
|00001580| 69 6e 74 65 72 76 61 6c | 20 6f 66 20 76 61 6c 75 |interval| of valu|
|00001590| 65 73 20 74 68 61 74 20 | 6d 69 67 68 74 20 62 65 |es that |might be|
|000015a0| 0d 69 6e 74 65 72 65 73 | 74 69 6e 67 2e 20 20 49 |.interes|ting. I|
|000015b0| 20 61 70 70 6c 79 20 74 | 68 61 74 20 69 6e 74 65 | apply t|hat inte|
|000015c0| 72 76 61 6c 20 74 6f 20 | 74 68 65 20 63 61 73 65 |rval to |the case|
|000015d0| 20 73 74 61 74 65 6d 65 | 6e 74 2c 20 61 6e 64 20 | stateme|nt, and |
|000015e0| 69 66 20 74 68 65 72 65 | 0d 63 61 6e 20 62 65 20 |if there|.can be |
|000015f0| 61 6e 79 20 6d 61 74 63 | 68 2c 20 49 20 63 72 65 |any matc|h, I cre|
|00001600| 61 74 65 20 61 6e 64 20 | 61 64 64 20 61 20 6e 65 |ate and |add a ne|
|00001610| 77 20 63 68 69 6c 64 20 | 6e 6f 64 65 2e 0d 3c 3c |w child |node..<<|
|00001620| 2a 3e 3e 3d 0d 70 72 6f | 63 65 64 75 72 65 20 73 |*>>=.pro|cedure s|
|00001630| 70 6c 69 74 28 6e 2c 20 | 66 29 0d 20 20 20 20 6c |plit(n, |f). l|
|00001640| 6f 63 61 6c 20 76 61 6c | 73 2c 76 2c 64 2c 76 61 |ocal val|s,v,d,va|
|00001650| 6c 2c 63 2c 70 2c 6a 2c | 69 2c 6e 65 77 64 2c 63 |l,c,p,j,|i,newd,c|
|00001660| 73 74 2c 63 68 69 6c 64 | 2c 6e 65 77 70 0d 0d 20 |st,child|,newp.. |
|00001670| 20 20 20 70 61 74 74 65 | 72 6e 73 20 3a 3d 20 5b | patte|rns := [|
|00001680| 5d 0d 20 20 20 20 63 68 | 69 6c 64 72 65 6e 20 3a |]. ch|ildren :|
|00001690| 3d 20 5b 5d 0d 20 20 20 | 20 65 76 65 72 79 20 70 |= []. | every p|
|000016a0| 75 74 28 70 61 74 74 65 | 72 6e 73 2c 20 28 21 6e |ut(patte|rns, (!n|
|000016b0| 2e 63 73 2e 61 72 6d 73 | 29 2e 70 61 74 74 65 72 |.cs.arms|).patter|
|000016c0| 6e 29 0d 20 20 20 20 72 | 20 3a 3d 20 69 6e 74 65 |n). r| := inte|
|000016d0| 72 76 61 6c 73 28 70 61 | 74 74 65 72 6e 73 2c 20 |rvals(pa|tterns, |
|000016e0| 66 29 0d 20 20 20 20 3c | 3c 69 66 20 64 65 62 75 |f). <|<if debu|
|000016f0| 67 67 69 6e 67 2c 20 77 | 72 69 74 65 20 61 62 6f |gging, w|rite abo|
|00001700| 75 74 20 73 70 6c 69 74 | 74 69 6e 67 20 74 68 69 |ut split|ting thi|
|00001710| 73 20 6e 6f 64 65 3e 3e | 0d 0d 20 20 20 20 65 76 |s node>>|.. ev|
|00001720| 65 72 79 20 69 20 3a 3d | 20 31 20 74 6f 20 2a 72 |ery i :=| 1 to *r|
|00001730| 20 2d 20 31 20 64 6f 0d | 20 20 20 20 20 20 20 20 | - 1 do.| |
|00001740| 70 75 74 28 63 68 69 6c | 64 72 65 6e 2c 20 65 64 |put(chil|dren, ed|
|00001750| 67 65 28 6e 6f 64 65 28 | 61 70 70 6c 79 28 6e 2e |ge(node(|apply(n.|
|00001760| 63 73 2c 20 66 2c 20 72 | 5b 69 5d 2c 20 72 5b 69 |cs, f, r|[i], r[i|
|00001770| 2b 31 5d 29 2c 5b 5d 29 | 2c 20 72 5b 69 5d 2c 20 |+1]),[])|, r[i], |
|00001780| 72 5b 69 2b 31 5d 29 29 | 0d 0d 20 20 20 20 77 72 |r[i+1]))|.. wr|
|00001790| 69 74 65 28 5c 73 64 65 | 62 75 67 2c 20 22 44 6f |ite(\sde|bug, "Do|
|000017a0| 6e 65 20 73 70 6c 69 74 | 74 69 6e 67 2e 5c 6e 22 |ne split|ting.\n"|
|000017b0| 29 0d 20 20 20 20 72 65 | 74 75 72 6e 20 63 68 69 |). re|turn chi|
|000017c0| 6c 64 72 65 6e 0d 65 6e | 64 20 20 20 20 0d 3c 3c |ldren.en|d .<<|
|000017d0| 69 66 20 64 65 62 75 67 | 67 69 6e 67 2c 20 77 72 |if debug|ging, wr|
|000017e0| 69 74 65 20 61 62 6f 75 | 74 20 73 70 6c 69 74 74 |ite abou|t splitt|
|000017f0| 69 6e 67 20 74 68 69 73 | 20 6e 6f 64 65 3e 3e 3d |ing this| node>>=|
|00001800| 0d 77 72 69 74 65 73 28 | 5c 73 64 65 62 75 67 2c |.writes(|\sdebug,|
|00001810| 20 22 53 70 6c 69 74 74 | 69 6e 67 20 22 29 0d 6f | "Splitt|ing ").o|
|00001820| 75 74 70 61 74 74 65 72 | 6e 28 5c 73 64 65 62 75 |utpatter|n(\sdebu|
|00001830| 67 2c 20 70 61 74 74 65 | 72 6e 73 5b 31 5d 29 0d |g, patte|rns[1]).|
|00001840| 65 76 65 72 79 20 69 20 | 3a 3d 20 32 20 74 6f 20 |every i |:= 2 to |
|00001850| 2a 70 61 74 74 65 72 6e | 73 20 64 6f 20 7b 20 77 |*pattern|s do { w|
|00001860| 72 69 74 65 73 28 5c 73 | 64 65 62 75 67 2c 20 22 |rites(\s|debug, "|
|00001870| 20 7c 20 22 29 3b 20 6f | 75 74 70 61 74 74 65 72 | | "); o|utpatter|
|00001880| 6e 28 5c 73 64 65 62 75 | 67 2c 20 70 61 74 74 65 |n(\sdebu|g, patte|
|00001890| 72 6e 73 5b 69 5d 29 7d | 0d 77 72 69 74 65 28 5c |rns[i])}|.write(\|
|000018a0| 73 64 65 62 75 67 2c 20 | 22 20 6f 6e 20 22 2c 20 |sdebug, |" on ", |
|000018b0| 66 2e 6e 61 6d 65 29 0d | 40 0d 53 6f 2c 20 77 68 |f.name).|@.So, wh|
|000018c0| 61 74 20 69 73 20 74 68 | 65 20 6e 65 77 20 63 61 |at is th|e new ca|
|000018d0| 73 65 20 73 74 61 74 65 | 6d 65 6e 74 20 74 68 61 |se state|ment tha|
|000018e0| 74 20 72 65 73 75 6c 74 | 73 20 66 72 6f 6d 20 61 |t result|s from a|
|000018f0| 70 70 6c 79 69 6e 67 20 | 0d 24 5c 74 74 20 6c 6f |pplying |.$\tt lo|
|00001900| 20 5c 6c 65 20 66 20 3c | 20 68 69 24 20 74 6f 20 | \le f <| hi$ to |
|00001910| 5b 5b 63 73 5d 5d 3f 0d | 46 6f 72 20 65 61 63 68 |[[cs]]?.|For each|
|00001920| 20 61 72 6d 2c 20 49 20 | 6d 61 74 63 68 20 74 68 | arm, I |match th|
|00001930| 65 20 70 61 74 74 65 72 | 6e 20 61 67 61 69 6e 73 |e patter|n agains|
|00001940| 74 20 74 68 65 20 69 6e | 74 65 72 76 61 6c 2e 0d |t the in|terval..|
|00001950| 49 66 20 69 74 20 73 75 | 63 63 65 65 64 73 2c 20 |If it su|cceeds, |
|00001960| 49 20 63 72 65 61 74 65 | 20 61 20 6e 65 77 20 61 |I create| a new a|
|00001970| 72 6d 20 66 6f 72 20 74 | 68 65 20 6e 65 77 20 63 |rm for t|he new c|
|00001980| 61 73 65 20 73 74 61 74 | 65 6d 65 6e 74 2c 0d 63 |ase stat|ement,.c|
|00001990| 6f 6e 74 61 69 6e 69 6e | 67 20 74 68 65 20 72 65 |ontainin|g the re|
|000019a0| 64 75 63 65 64 20 70 61 | 74 74 65 72 6e 2e 0d 3c |duced pa|ttern..<|
|000019b0| 3c 2a 3e 3e 3d 0d 70 72 | 6f 63 65 64 75 72 65 20 |<*>>=.pr|ocedure |
|000019c0| 61 70 70 6c 79 28 63 73 | 2c 20 66 2c 20 6c 6f 2c |apply(cs|, f, lo,|
|000019d0| 20 68 69 29 0d 20 20 20 | 20 72 65 73 75 6c 74 20 | hi). | result |
|000019e0| 3a 3d 20 63 6f 70 79 28 | 63 73 29 0d 20 20 20 20 |:= copy(|cs). |
|000019f0| 72 65 73 75 6c 74 2e 61 | 72 6d 73 20 3a 3d 20 5b |result.a|rms := [|
|00001a00| 5d 0d 20 20 20 20 77 72 | 69 74 65 28 5c 73 64 65 |]. wr|ite(\sde|
|00001a10| 62 75 67 2c 20 22 20 20 | 20 20 41 70 70 6c 79 69 |bug, " | Applyi|
|00001a20| 6e 67 20 22 2c 20 73 74 | 72 69 6e 67 69 6e 69 6e |ng ", st|ringinin|
|00001a30| 74 65 72 76 61 6c 28 66 | 2e 6e 61 6d 65 2c 20 6c |terval(f|.name, l|
|00001a40| 6f 2c 20 68 69 29 29 0d | 20 20 20 20 65 76 65 72 |o, hi)).| ever|
|00001a50| 79 20 61 20 3a 3d 20 21 | 63 73 2e 61 72 6d 73 20 |y a := !|cs.arms |
|00001a60| 64 6f 0d 20 20 20 20 20 | 20 20 20 70 75 74 28 72 |do. | put(r|
|00001a70| 65 73 75 6c 74 2e 61 72 | 6d 73 2c 20 0d 20 20 20 |esult.ar|ms, . |
|00001a80| 20 20 20 20 20 20 20 20 | 20 61 72 6d 28 61 2e 66 | | arm(a.f|
|00001a90| 69 6c 65 2c 20 61 2e 6c | 69 6e 65 2c 20 70 6d 61 |ile, a.l|ine, pma|
|00001aa0| 74 63 68 28 61 2e 70 61 | 74 74 65 72 6e 2c 20 66 |tch(a.pa|ttern, f|
|00001ab0| 2c 20 6c 6f 2c 20 68 69 | 29 2c 20 61 2e 63 6f 64 |, lo, hi|), a.cod|
|00001ac0| 65 2c 20 61 2e 6f 72 69 | 67 69 6e 61 6c 29 29 0d |e, a.ori|ginal)).|
|00001ad0| 20 20 20 20 69 66 20 61 | 6c 77 61 79 73 6d 61 74 | if a|lwaysmat|
|00001ae0| 63 68 65 73 28 72 65 73 | 75 6c 74 2e 61 72 6d 73 |ches(res|ult.arms|
|00001af0| 5b 31 5d 2e 70 61 74 74 | 65 72 6e 29 20 74 68 65 |[1].patt|ern) the|
|00001b00| 6e 0d 20 20 20 20 20 20 | 20 20 72 65 73 75 6c 74 |n. | result|
|00001b10| 2e 61 72 6d 73 20 3a 3d | 20 5b 72 65 73 75 6c 74 |.arms :=| [result|
|00001b20| 2e 61 72 6d 73 5b 31 5d | 5d 0d 20 20 20 20 72 65 |.arms[1]|]. re|
|00001b30| 74 75 72 6e 20 72 65 73 | 75 6c 74 0d 65 6e 64 0d |turn res|ult.end.|
|00001b40| 0d 23 20 69 66 20 6c 6f | 20 3c 3d 20 66 20 3c 20 |.# if lo| <= f < |
|00001b50| 68 69 20 61 6e 64 20 70 | 20 6d 61 74 63 68 65 73 |hi and p| matches|
|00001b60| 2c 20 72 65 74 75 72 6e | 20 74 68 65 20 6e 65 77 |, return| the new|
|00001b70| 20 70 0d 0d 70 72 6f 63 | 65 64 75 72 65 20 70 6d | p..proc|edure pm|
|00001b80| 61 74 63 68 28 70 2c 20 | 66 2c 20 6c 6f 2c 20 68 |atch(p, |f, lo, h|
|00001b90| 69 29 0d 20 20 20 20 72 | 65 73 75 6c 74 20 3a 3d |i). r|esult :=|
|00001ba0| 20 70 61 74 74 65 72 6e | 28 5b 5d 2c 20 70 2e 6e | pattern|([], p.n|
|00001bb0| 61 6d 65 29 0d 20 20 20 | 20 65 76 65 72 79 20 64 |ame). | every d|
|00001bc0| 20 3a 3d 20 21 70 2e 64 | 69 73 6a 75 6e 63 74 73 | := !p.d|isjuncts|
|00001bd0| 20 64 6f 20 0d 20 20 20 | 20 20 20 20 20 69 66 20 | do . | if |
|00001be0| 63 20 3a 3d 20 21 64 2e | 63 6f 6e 73 74 72 61 69 |c := !d.|constrai|
|00001bf0| 6e 74 73 20 26 20 63 2e | 66 69 65 6c 64 20 3d 3d |nts & c.|field ==|
|00001c00| 3d 20 66 20 74 68 65 6e | 20 09 23 20 64 69 73 6a |= f then| .# disj|
|00001c10| 75 6e 63 74 20 6d 65 6e | 74 69 6f 6e 73 20 66 0d |unct men|tions f.|
|00001c20| 09 20 20 20 20 69 66 20 | 63 2e 6c 6f 20 3c 3d 20 |. if |c.lo <= |
|00001c30| 6c 6f 20 26 20 68 69 20 | 3c 3d 20 63 2e 68 69 20 |lo & hi |<= c.hi |
|00001c40| 74 68 65 6e 20 7b 20 09 | 09 23 20 74 68 69 73 20 |then { .|.# this |
|00001c50| 63 6f 6e 73 74 72 61 69 | 6e 74 20 69 73 20 6d 61 |constrai|nt is ma|
|00001c60| 74 63 68 65 64 0d 09 09 | 6e 65 77 64 20 3a 3d 20 |tched...|newd := |
|00001c70| 64 69 73 6a 75 6e 63 74 | 28 5b 5d 2c 20 64 2e 6e |disjunct|([], d.n|
|00001c80| 61 6d 65 29 0d 09 09 65 | 76 65 72 79 20 63 20 3a |ame)...e|very c :|
|00001c90| 3d 20 21 64 2e 63 6f 6e | 73 74 72 61 69 6e 74 73 |= !d.con|straints|
|00001ca0| 20 26 20 63 2e 66 69 65 | 6c 64 20 7e 3d 3d 3d 20 | & c.fie|ld ~=== |
|00001cb0| 66 20 64 6f 20 0d 09 09 | 20 20 20 20 70 75 74 28 |f do ...| put(|
|00001cc0| 6e 65 77 64 2e 63 6f 6e | 73 74 72 61 69 6e 74 73 |newd.con|straints|
|00001cd0| 2c 20 63 29 0d 09 09 70 | 75 74 28 72 65 73 75 6c |, c)...p|ut(resul|
|00001ce0| 74 2e 64 69 73 6a 75 6e | 63 74 73 2c 20 6e 65 77 |t.disjun|cts, new|
|00001cf0| 64 29 0d 09 20 20 20 20 | 7d 20 65 6c 73 65 0d 09 |d).. |} else..|
|00001d00| 09 63 2e 68 69 20 3c 3d | 20 6c 6f 20 7c 20 63 2e |.c.hi <=| lo | c.|
|00001d10| 6c 6f 20 3e 3d 20 68 69 | 20 7c 20 69 6d 70 6f 73 |lo >= hi| | impos|
|00001d20| 73 69 62 6c 65 28 22 62 | 61 64 20 69 6e 74 65 72 |sible("b|ad inter|
|00001d30| 76 61 6c 73 22 29 0d 20 | 20 20 20 20 20 20 20 65 |vals"). | e|
|00001d40| 6c 73 65 09 09 09 09 09 | 09 20 23 20 64 69 73 6a |lse.....|. # disj|
|00001d50| 75 6e 63 74 20 64 6f 65 | 73 20 6e 6f 74 20 6d 65 |unct doe|s not me|
|00001d60| 6e 74 69 6f 6e 20 66 0d | 09 20 20 20 20 70 75 74 |ntion f.|. put|
|00001d70| 28 72 65 73 75 6c 74 2e | 64 69 73 6a 75 6e 63 74 |(result.|disjunct|
|00001d80| 73 2c 20 64 29 0d 20 20 | 20 20 3c 3c 69 66 20 64 |s, d). | <<if d|
|00001d90| 65 62 75 67 67 69 6e 67 | 2c 20 77 72 69 74 65 20 |ebugging|, write |
|00001da0| 61 62 6f 75 74 20 72 65 | 73 75 6c 74 73 20 6f 66 |about re|sults of|
|00001db0| 20 5b 5b 70 6d 61 74 63 | 68 5d 5d 3e 3e 0d 20 20 | [[pmatc|h]]>>. |
|00001dc0| 20 20 69 66 20 2a 72 65 | 73 75 6c 74 2e 64 69 73 | if *re|sult.dis|
|00001dd0| 6a 75 6e 63 74 73 20 3e | 20 30 20 74 68 65 6e 20 |juncts >| 0 then |
|00001de0| 72 65 74 75 72 6e 20 72 | 65 73 75 6c 74 0d 65 6e |return r|esult.en|
|00001df0| 64 0d 0d 3c 3c 69 66 20 | 64 65 62 75 67 67 69 6e |d..<<if |debuggin|
|00001e00| 67 2c 20 77 72 69 74 65 | 20 61 62 6f 75 74 20 72 |g, write| about r|
|00001e10| 65 73 75 6c 74 73 20 6f | 66 20 5b 5b 70 6d 61 74 |esults o|f [[pmat|
|00001e20| 63 68 5d 5d 3e 3e 3d 0d | 69 66 20 2a 72 65 73 75 |ch]]>>=.|if *resu|
|00001e30| 6c 74 2e 64 69 73 6a 75 | 6e 63 74 73 20 3e 20 30 |lt.disju|ncts > 0|
|00001e40| 20 74 68 65 6e 20 77 72 | 69 74 65 73 28 5c 73 64 | then wr|ites(\sd|
|00001e50| 65 62 75 67 2c 20 22 20 | 20 20 20 20 20 20 20 3d |ebug, " | =|
|00001e60| 3d 3d 3e 20 22 29 20 26 | 20 6f 75 74 70 61 74 74 |==> ") &| outpatt|
|00001e70| 65 72 6e 28 5c 73 64 65 | 62 75 67 2c 20 70 29 0d |ern(\sde|bug, p).|
|00001e80| 23 20 65 6c 73 65 20 77 | 72 69 74 65 73 28 5c 73 |# else w|rites(\s|
|00001e90| 64 65 62 75 67 2c 20 22 | 20 20 20 20 20 20 20 20 |debug, "| |
|00001ea0| 20 20 20 20 20 22 29 20 | 26 20 6f 75 74 70 61 74 | ") |& outpat|
|00001eb0| 74 65 72 6e 28 5c 73 64 | 65 62 75 67 2c 20 70 29 |tern(\sd|ebug, p)|
|00001ec0| 0d 0d 69 66 20 2a 72 65 | 73 75 6c 74 2e 64 69 73 |..if *re|sult.dis|
|00001ed0| 6a 75 6e 63 74 73 20 3e | 20 30 20 74 68 65 6e 20 |juncts >| 0 then |
|00001ee0| 77 72 69 74 65 28 5c 73 | 64 65 62 75 67 2c 20 22 |write(\s|debug, "|
|00001ef0| 20 6d 61 74 63 68 65 73 | 22 29 20 0d 23 20 65 6c | matches|") .# el|
|00001f00| 73 65 20 77 72 69 74 65 | 28 5c 73 64 65 62 75 67 |se write|(\sdebug|
|00001f10| 2c 20 22 20 64 6f 65 73 | 20 6e 6f 74 20 6d 61 74 |, " does| not mat|
|00001f20| 63 68 22 29 0d 40 0d 5c | 73 75 62 73 65 63 74 69 |ch").@.\|subsecti|
|00001f30| 6f 6e 7b 54 72 65 65 2d | 6d 69 6e 69 6d 69 7a 61 |on{Tree-|minimiza|
|00001f40| 74 69 6f 6e 20 68 65 75 | 72 69 73 74 69 63 73 7d |tion heu|ristics}|
|00001f50| 0d 46 69 72 73 74 2c 20 | 74 68 65 20 62 6f 69 6c |.First, |the boil|
|00001f60| 65 72 70 6c 61 74 65 20 | 74 68 61 74 20 74 61 6b |erplate |that tak|
|00001f70| 65 73 20 61 20 68 65 75 | 72 69 73 74 69 63 20 5b |es a heu|ristic [|
|00001f80| 5b 68 5d 5d 2c 20 63 61 | 6e 64 69 64 61 74 65 0d |[h]], ca|ndidate.|
|00001f90| 73 70 6c 69 74 74 69 6e | 67 73 2c 20 61 6e 64 20 |splittin|gs, and |
|00001fa0| 61 20 73 65 74 20 6f 66 | 20 66 69 65 6c 64 73 2c |a set of| fields,|
|00001fb0| 20 61 6e 64 20 72 65 74 | 75 72 6e 73 20 74 68 65 | and ret|urns the|
|00001fc0| 20 73 65 74 20 6f 66 20 | 66 69 65 6c 64 73 20 77 | set of |fields w|
|00001fd0| 69 74 68 0d 74 68 65 20 | 6c 61 72 67 65 73 74 20 |ith.the |largest |
|00001fe0| 73 63 6f 72 65 20 6f 6e | 20 5b 5b 68 5d 5d 2e 0d |score on| [[h]]..|
|00001ff0| 3c 3c 2a 3e 3e 3d 0d 70 | 72 6f 63 65 64 75 72 65 |<<*>>=.p|rocedure|
|00002000| 20 66 69 6e 64 6d 61 78 | 69 6d 61 28 68 2c 20 63 | findmax|ima(h, c|
|00002010| 61 6e 64 69 64 61 74 65 | 73 2c 20 66 69 65 6c 64 |andidate|s, field|
|00002020| 73 29 0d 20 20 20 20 6c | 6f 63 61 6c 20 6d 61 78 |s). l|ocal max|
|00002030| 0d 20 20 20 20 53 20 3a | 3d 20 5b 5d 0d 20 20 20 |. S :|= []. |
|00002040| 20 65 76 65 72 79 20 66 | 20 3a 3d 20 21 66 69 65 | every f| := !fie|
|00002050| 6c 64 73 20 64 6f 20 7b | 0d 09 73 63 6f 72 65 20 |lds do {|..score |
|00002060| 3a 3d 20 68 28 63 61 6e | 64 69 64 61 74 65 73 5b |:= h(can|didates[|
|00002070| 66 5d 2c 20 66 29 0d 20 | 20 20 20 20 20 20 20 77 |f], f). | w|
|00002080| 72 69 74 65 28 5c 68 64 | 65 62 75 67 2c 22 46 69 |rite(\hd|ebug,"Fi|
|00002090| 65 6c 64 20 22 2c 20 66 | 2e 6e 61 6d 65 2c 20 22 |eld ", f|.name, "|
|000020a0| 20 73 63 6f 72 65 73 20 | 22 2c 20 73 63 6f 72 65 | scores |", score|
|000020b0| 2c 20 22 20 6f 6e 20 22 | 2c 20 69 6d 61 67 65 28 |, " on "|, image(|
|000020c0| 68 29 29 0d 09 2f 6d 61 | 78 20 3a 3d 20 73 63 6f |h))../ma|x := sco|
|000020d0| 72 65 20 2d 20 31 0d 09 | 69 66 20 73 63 6f 72 65 |re - 1..|if score|
|000020e0| 20 3e 20 6d 61 78 20 74 | 68 65 6e 20 7b 0d 09 20 | > max t|hen {.. |
|000020f0| 20 20 20 6d 61 78 20 3a | 3d 20 73 63 6f 72 65 0d | max :|= score.|
|00002100| 09 20 20 20 20 53 20 3a | 3d 20 5b 66 5d 0d 09 7d |. S :|= [f]..}|
|00002110| 20 65 6c 73 65 20 69 66 | 20 73 63 6f 72 65 20 3d | else if| score =|
|00002120| 20 6d 61 78 20 74 68 65 | 6e 0d 09 20 20 20 20 70 | max the|n.. p|
|00002130| 75 74 28 53 2c 20 66 29 | 0d 20 20 20 20 7d 0d 20 |ut(S, f)|. }. |
|00002140| 20 20 20 72 65 74 75 72 | 6e 20 73 65 74 28 53 29 | retur|n set(S)|
|00002150| 0d 65 6e 64 0d 40 0d 48 | 65 72 65 27 73 20 61 20 |.end.@.H|ere's a |
|00002160| 62 69 67 20 70 69 6c 65 | 20 6f 66 20 68 65 75 72 |big pile| of heur|
|00002170| 69 73 74 69 63 73 2e 0d | 49 27 6d 20 6e 6f 74 20 |istics..|I'm not |
|00002180| 73 75 72 65 20 49 27 76 | 65 20 65 76 65 72 20 6e |sure I'v|e ever n|
|00002190| 65 65 64 65 64 20 6d 6f | 72 65 20 74 68 61 6e 20 |eeded mo|re than |
|000021a0| 74 68 65 20 66 69 72 73 | 74 20 74 77 6f 2c 20 62 |the firs|t two, b|
|000021b0| 75 74 20 74 68 65 79 27 | 72 65 0d 61 6d 75 73 69 |ut they'|re.amusi|
|000021c0| 6e 67 20 61 6e 64 20 65 | 61 73 79 20 65 6e 6f 75 |ng and e|asy enou|
|000021d0| 67 68 20 74 6f 20 77 72 | 69 74 65 2e 0d 3c 3c 2a |gh to wr|ite..<<*|
|000021e0| 3e 3e 3d 0d 23 20 6c 65 | 61 66 61 72 6d 73 3a 20 |>>=.# le|afarms: |
|000021f0| 70 72 65 66 65 72 20 63 | 61 6e 64 69 64 61 74 65 |prefer c|andidate|
|00002200| 20 77 69 74 68 20 6d 6f | 73 74 20 61 72 6d 73 20 | with mo|st arms |
|00002210| 74 68 61 74 20 61 70 70 | 65 61 72 20 61 74 20 6c |that app|ear at l|
|00002220| 65 61 66 0d 23 20 20 20 | 20 20 20 20 20 20 20 20 |eaf.# | |
|00002230| 6e 6f 64 65 73 2e 20 20 | 45 61 63 68 20 6f 72 69 |nodes. |Each ori|
|00002240| 67 69 6e 61 6c 20 61 72 | 6d 20 63 6f 75 6e 74 65 |ginal ar|m counte|
|00002250| 64 20 6f 6e 6c 79 20 6f | 6e 63 65 2e 0d 23 09 20 |d only o|nce..#. |
|00002260| 20 20 20 4e 6f 74 20 6d | 61 74 63 68 69 6e 67 20 | Not m|atching |
|00002270| 69 73 20 61 6c 73 6f 20 | 63 6f 75 6e 74 65 64 20 |is also |counted |
|00002280| 61 73 20 61 6e 20 61 72 | 6d 2e 0d 0d 70 72 6f 63 |as an ar|m...proc|
|00002290| 65 64 75 72 65 20 6c 65 | 61 66 61 72 6d 73 28 63 |edure le|afarms(c|
|000022a0| 68 69 6c 64 72 65 6e 2c | 20 66 29 20 0d 20 20 20 |hildren,| f) . |
|000022b0| 20 61 72 6d 73 20 3a 3d | 20 73 65 74 28 29 0d 20 | arms :=| set(). |
|000022c0| 20 20 20 65 76 65 72 79 | 20 6e 20 3a 3d 20 28 21 | every| n := (!|
|000022d0| 63 68 69 6c 64 72 65 6e | 29 2e 6e 6f 64 65 20 26 |children|).node &|
|000022e0| 20 2a 6e 2e 63 73 2e 61 | 72 6d 73 20 3e 20 30 20 | *n.cs.a|rms > 0 |
|000022f0| 64 6f 0d 20 20 20 20 20 | 20 20 69 66 20 6e 6f 74 |do. | if not|
|00002300| 20 6e 65 65 64 73 5f 73 | 70 6c 69 74 74 69 6e 67 | needs_s|plitting|
|00002310| 28 6e 29 20 74 68 65 6e | 20 0d 20 20 20 20 20 20 |(n) then| . |
|00002320| 20 20 20 20 20 69 6e 73 | 65 72 74 28 61 72 6d 73 | ins|ert(arms|
|00002330| 2c 20 6e 2e 63 73 2e 61 | 72 6d 73 5b 31 5d 2e 6f |, n.cs.a|rms[1].o|
|00002340| 72 69 67 69 6e 61 6c 29 | 0d 20 20 20 20 72 65 74 |riginal)|. ret|
|00002350| 75 72 6e 20 2a 61 72 6d | 73 20 2b 20 69 66 20 2a |urn *arm|s + if *|
|00002360| 28 21 63 68 69 6c 64 72 | 65 6e 29 2e 6e 6f 64 65 |(!childr|en).node|
|00002370| 2e 63 73 2e 61 72 6d 73 | 20 3d 20 30 20 74 68 65 |.cs.arms| = 0 the|
|00002380| 6e 20 31 20 65 6c 73 65 | 20 30 0d 65 6e 64 0d 0d |n 1 else| 0.end..|
|00002390| 23 20 63 68 69 6c 64 61 | 72 6d 73 3a 20 70 72 65 |# childa|rms: pre|
|000023a0| 66 65 72 20 74 68 65 20 | 63 61 6e 64 69 64 61 74 |fer the |candidat|
|000023b0| 65 20 77 69 74 68 20 74 | 68 65 20 66 65 77 65 73 |e with t|he fewes|
|000023c0| 74 20 61 72 6d 73 20 69 | 6e 20 63 68 69 6c 64 72 |t arms i|n childr|
|000023d0| 65 6e 0d 0d 70 72 6f 63 | 65 64 75 72 65 20 63 68 |en..proc|edure ch|
|000023e0| 69 6c 64 61 72 6d 73 28 | 63 68 69 6c 64 72 65 6e |ildarms(|children|
|000023f0| 2c 20 66 29 0d 20 20 20 | 20 73 75 6d 20 3a 3d 20 |, f). | sum := |
|00002400| 30 0d 20 20 20 20 65 76 | 65 72 79 20 73 75 6d 20 |0. ev|ery sum |
|00002410| 2d 3a 3d 20 2a 28 21 63 | 68 69 6c 64 72 65 6e 29 |-:= *(!c|hildren)|
|00002420| 2e 6e 6f 64 65 2e 63 73 | 2e 61 72 6d 73 0d 20 20 |.node.cs|.arms. |
|00002430| 20 20 72 65 74 75 72 6e | 20 73 75 6d 0d 65 6e 64 | return| sum.end|
|00002440| 0d 0d 23 20 6e 6f 6d 61 | 74 63 68 3a 20 69 66 20 |..# noma|tch: if |
|00002450| 74 69 65 64 20 6f 6e 20 | 6c 65 61 66 61 72 6d 73 |tied on |leafarms|
|00002460| 20 61 6e 64 20 63 68 69 | 6c 64 61 72 6d 73 2c 20 | and chi|ldarms, |
|00002470| 74 61 6b 65 20 63 61 6e | 64 69 64 61 74 65 0d 23 |take can|didate.#|
|00002480| 20 20 20 20 20 20 20 20 | 20 20 77 69 74 68 20 72 | | with r|
|00002490| 65 61 6c 20 6c 65 61 66 | 20 69 6e 20 70 72 65 66 |eal leaf| in pref|
|000024a0| 65 72 65 6e 63 65 20 74 | 6f 20 6e 6f 6d 61 74 63 |erence t|o nomatc|
|000024b0| 68 20 6c 65 61 66 0d 0d | 70 72 6f 63 65 64 75 72 |h leaf..|procedur|
|000024c0| 65 20 6e 6f 6d 61 74 63 | 68 28 63 68 69 6c 64 72 |e nomatc|h(childr|
|000024d0| 65 6e 2c 20 66 29 0d 20 | 20 20 20 72 65 74 75 72 |en, f). | retur|
|000024e0| 6e 20 69 66 20 2a 28 21 | 63 68 69 6c 64 72 65 6e |n if *(!|children|
|000024f0| 29 2e 6e 6f 64 65 2e 63 | 73 2e 61 72 6d 73 20 3d |).node.c|s.arms =|
|00002500| 20 30 20 74 68 65 6e 20 | 2d 31 20 65 6c 73 65 20 | 0 then |-1 else |
|00002510| 30 0d 65 6e 64 0d 0d 23 | 20 63 68 69 6c 64 64 69 |0.end..#| childdi|
|00002520| 73 6a 75 6e 63 74 73 3a | 20 70 72 65 66 65 72 20 |sjuncts:| prefer |
|00002530| 74 68 65 20 63 61 6e 64 | 69 64 61 74 65 20 77 69 |the cand|idate wi|
|00002540| 74 68 20 74 68 65 20 66 | 65 77 65 73 74 20 64 69 |th the f|ewest di|
|00002550| 73 6a 75 6e 63 74 73 20 | 69 6e 20 63 68 69 6c 64 |sjuncts |in child|
|00002560| 72 65 6e 0d 0d 70 72 6f | 63 65 64 75 72 65 20 63 |ren..pro|cedure c|
|00002570| 68 69 6c 64 64 69 73 6a | 75 6e 63 74 73 28 63 68 |hilddisj|uncts(ch|
|00002580| 69 6c 64 72 65 6e 2c 20 | 66 29 0d 20 20 20 20 73 |ildren, |f). s|
|00002590| 75 6d 20 3a 3d 20 30 0d | 20 20 20 20 65 76 65 72 |um := 0.| ever|
|000025a0| 79 20 73 75 6d 20 2d 3a | 3d 20 2a 28 21 28 21 63 |y sum -:|= *(!(!c|
|000025b0| 68 69 6c 64 72 65 6e 29 | 2e 6e 6f 64 65 2e 63 73 |hildren)|.node.cs|
|000025c0| 2e 61 72 6d 73 29 2e 70 | 61 74 74 65 72 6e 2e 64 |.arms).p|attern.d|
|000025d0| 69 73 6a 75 6e 63 74 73 | 0d 20 20 20 20 72 65 74 |isjuncts|. ret|
|000025e0| 75 72 6e 20 73 75 6d 0d | 65 6e 64 0d 0d 23 20 62 |urn sum.|end..# b|
|000025f0| 72 61 6e 63 68 66 61 63 | 74 6f 72 3a 20 20 70 72 |ranchfac|tor: pr|
|00002600| 65 66 65 72 20 74 68 65 | 20 63 61 6e 64 69 64 61 |efer the| candida|
|00002610| 74 65 20 77 69 74 68 20 | 74 68 65 20 66 65 77 65 |te with |the fewe|
|00002620| 73 74 20 63 68 69 6c 64 | 72 65 6e 0d 0d 70 72 6f |st child|ren..pro|
|00002630| 63 65 64 75 72 65 20 62 | 72 61 6e 63 68 66 61 63 |cedure b|ranchfac|
|00002640| 74 6f 72 28 63 68 69 6c | 64 72 65 6e 2c 20 66 29 |tor(chil|dren, f)|
|00002650| 0d 20 20 20 20 72 65 74 | 75 72 6e 20 2d 20 2a 63 |. ret|urn - *c|
|00002660| 68 69 6c 64 72 65 6e 0d | 65 6e 64 0d 40 0d 5c 73 |hildren.|end.@.\s|
|00002670| 75 62 73 65 63 74 69 6f | 6e 7b 55 74 69 6c 69 74 |ubsectio|n{Utilit|
|00002680| 79 20 66 75 6e 63 74 69 | 6f 6e 73 7d 0d 3c 3c 2a |y functi|ons}.<<*|
|00002690| 3e 3e 3d 0d 23 20 49 66 | 20 66 20 69 73 20 74 6f |>>=.# If| f is to|
|000026a0| 20 62 65 20 75 73 65 64 | 20 74 6f 20 73 70 6c 69 | be used| to spli|
|000026b0| 74 20 70 61 74 74 65 72 | 6e 73 2c 20 77 68 61 74 |t patter|ns, what|
|000026c0| 20 69 6e 74 65 72 76 61 | 6c 73 20 6e 65 65 64 20 | interva|ls need |
|000026d0| 74 6f 20 62 65 20 63 6f | 6e 73 69 64 65 72 65 64 |to be co|nsidered|
|000026e0| 3f 0d 0d 70 72 6f 63 65 | 64 75 72 65 20 69 6e 74 |?..proce|dure int|
|000026f0| 65 72 76 61 6c 73 28 70 | 61 74 74 65 72 6e 73 2c |ervals(p|atterns,|
|00002700| 20 66 29 0d 20 20 20 20 | 63 75 74 73 20 3a 3d 20 | f). |cuts := |
|00002710| 73 65 74 28 5b 30 2c 20 | 32 5e 28 66 2e 68 69 20 |set([0, |2^(f.hi |
|00002720| 2d 20 66 2e 6c 6f 29 5d | 29 0d 20 20 20 20 65 76 |- f.lo)]|). ev|
|00002730| 65 72 79 20 70 20 3a 3d | 20 21 70 61 74 74 65 72 |ery p :=| !patter|
|00002740| 6e 73 20 26 20 64 20 3a | 3d 20 21 70 2e 64 69 73 |ns & d :|= !p.dis|
|00002750| 6a 75 6e 63 74 73 20 26 | 20 63 20 3a 3d 20 21 64 |juncts &| c := !d|
|00002760| 2e 63 6f 6e 73 74 72 61 | 69 6e 74 73 20 26 20 63 |.constra|ints & c|
|00002770| 2e 66 69 65 6c 64 20 3d | 3d 3d 20 66 20 64 6f 0d |.field =|== f do.|
|00002780| 09 65 76 65 72 79 20 69 | 6e 73 65 72 74 28 63 75 |.every i|nsert(cu|
|00002790| 74 73 2c 20 63 2e 6c 6f | 20 7c 20 63 2e 68 69 29 |ts, c.lo| | c.hi)|
|000027a0| 0d 20 20 20 20 72 65 74 | 75 72 6e 20 73 6f 72 74 |. ret|urn sort|
|000027b0| 28 63 75 74 73 29 0d 65 | 6e 64 0d 0d 23 20 77 68 |(cuts).e|nd..# wh|
|000027c0| 61 74 20 66 69 65 6c 64 | 73 20 61 72 65 20 6d 65 |at field|s are me|
|000027d0| 6e 74 69 6f 6e 65 64 20 | 69 6e 20 61 20 63 61 73 |ntioned |in a cas|
|000027e0| 65 20 73 74 61 74 65 6d | 65 6e 74 3f 0d 0d 70 72 |e statem|ent?..pr|
|000027f0| 6f 63 65 64 75 72 65 20 | 6d 65 6e 74 69 6f 6e 73 |ocedure |mentions|
|00002800| 28 63 73 29 20 0d 20 20 | 20 20 72 65 73 75 6c 74 |(cs) . | result|
|00002810| 20 3a 3d 20 73 65 74 28 | 29 0d 20 20 20 20 65 76 | := set(|). ev|
|00002820| 65 72 79 20 61 20 3a 3d | 20 21 63 73 2e 61 72 6d |ery a :=| !cs.arm|
|00002830| 73 20 26 20 64 20 3a 3d | 20 21 61 2e 70 61 74 74 |s & d :=| !a.patt|
|00002840| 65 72 6e 2e 64 69 73 6a | 75 6e 63 74 73 20 26 20 |ern.disj|uncts & |
|00002850| 63 20 3a 3d 20 21 64 2e | 63 6f 6e 73 74 72 61 69 |c := !d.|constrai|
|00002860| 6e 74 73 20 64 6f 0d 20 | 20 20 20 20 20 20 69 6e |nts do. | in|
|00002870| 73 65 72 74 28 72 65 73 | 75 6c 74 2c 20 63 2e 66 |sert(res|ult, c.f|
|00002880| 69 65 6c 64 29 0d 20 20 | 20 20 72 65 74 75 72 6e |ield). | return|
|00002890| 20 72 65 73 75 6c 74 0d | 65 6e 64 0d 0d 23 20 66 | result.|end..# f|
|000028a0| 69 6e 64 5f 69 64 3a 20 | 74 61 62 20 74 6f 20 61 |ind_id: |tab to a|
|000028b0| 6e 64 20 70 61 73 74 20 | 69 64 65 6e 74 69 66 69 |nd past |identifi|
|000028c0| 65 72 20 69 64 2c 20 72 | 65 74 75 72 6e 69 6e 67 |er id, r|eturning|
|000028d0| 20 69 74 73 20 70 6f 73 | 69 74 69 6f 6e 0d 23 20 | its pos|ition.# |
|000028e0| 69 67 6e 6f 72 65 73 20 | 71 75 6f 74 65 73 2c 20 |ignores |quotes, |
|000028f0| 63 6f 6d 6d 65 6e 74 20 | 62 72 61 63 6b 65 74 73 |comment |brackets|
|00002900| 0d 0d 70 72 6f 63 65 64 | 75 72 65 20 66 69 6e 64 |..proced|ure find|
|00002910| 5f 69 64 28 69 64 29 0d | 20 20 20 20 73 74 61 74 |_id(id).| stat|
|00002920| 69 63 20 6e 6f 74 6c 6e | 75 6d 0d 20 20 20 20 69 |ic notln|um. i|
|00002930| 6e 69 74 69 61 6c 20 6e | 6f 74 6c 6e 75 6d 20 3a |nitial n|otlnum :|
|00002940| 3d 20 7e 20 28 26 6c 65 | 74 74 65 72 73 20 2b 2b |= ~ (&le|tters ++|
|00002950| 20 26 64 69 67 69 74 73 | 20 2b 2b 20 27 5f 27 29 | &digits| ++ '_')|
|00002960| 0d 20 20 20 20 74 61 62 | 28 70 20 3a 3d 20 66 69 |. tab|(p := fi|
|00002970| 6e 64 28 69 64 29 29 20 | 26 20 70 20 3d 20 31 20 |nd(id)) |& p = 1 |
|00002980| 7c 20 28 6d 6f 76 65 28 | 2d 31 29 20 26 20 61 6e || (move(|-1) & an|
|00002990| 79 28 6e 6f 74 6c 6e 75 | 6d 29 20 26 20 6d 6f 76 |y(notlnu|m) & mov|
|000029a0| 65 28 31 29 29 20 26 0d | 20 20 20 20 20 20 20 20 |e(1)) &.| |
|000029b0| 20 20 20 20 20 20 20 3d | 69 64 20 26 20 70 6f 73 | =|id & pos|
|000029c0| 28 30 29 20 7c 20 61 6e | 79 28 6e 6f 74 6c 6e 75 |(0) | an|y(notlnu|
|000029d0| 6d 29 20 26 20 73 75 73 | 70 65 6e 64 20 70 0d 65 |m) & sus|pend p.e|
|000029e0| 6e 64 0d 40 0d 5c 73 75 | 62 73 65 63 74 69 6f 6e |nd.@.\su|bsection|
|000029f0| 7b 54 72 65 65 20 63 68 | 65 63 6b 69 6e 67 7d 0d |{Tree ch|ecking}.|
|00002a00| 4f 6e 63 65 20 74 68 65 | 20 74 72 65 65 20 69 73 |Once the| tree is|
|00002a10| 20 67 65 6e 65 72 61 74 | 65 64 2c 20 69 74 27 73 | generat|ed, it's|
|00002a20| 20 75 73 65 66 75 6c 20 | 74 6f 20 63 68 65 63 6b | useful |to check|
|00002a30| 20 69 74 20 66 6f 72 20 | 72 65 64 75 6e 64 61 6e | it for |redundan|
|00002a40| 74 20 61 72 6d 73 0d 61 | 6e 64 20 66 6f 72 20 61 |t arms.a|nd for a|
|00002a50| 72 6d 73 20 74 68 61 74 | 20 6e 65 76 65 72 20 6d |rms that| never m|
|00002a60| 61 74 63 68 2e 20 20 54 | 68 65 73 65 20 63 68 65 |atch. T|hese che|
|00002a70| 63 6b 73 20 77 69 6c 6c | 20 68 65 6c 70 20 75 73 |cks will| help us|
|00002a80| 65 72 73 20 63 61 74 63 | 68 0d 6d 69 73 74 61 6b |ers catc|h.mistak|
|00002a90| 65 73 20 69 6e 20 74 68 | 65 69 72 20 73 70 65 63 |es in th|eir spec|
|00002aa0| 69 66 69 63 61 74 69 6f | 6e 73 2e 20 20 4e 6f 74 |ificatio|ns. Not|
|00002ab0| 65 20 74 68 61 74 20 49 | 20 6d 75 73 74 20 63 68 |e that I| must ch|
|00002ac0| 65 63 6b 20 74 68 65 0d | 60 60 6f 72 69 67 69 6e |eck the.|``origin|
|00002ad0| 61 6c 27 27 20 61 72 6d | 73 3b 20 74 68 61 74 27 |al'' arm|s; that'|
|00002ae0| 73 20 77 68 79 20 74 68 | 65 79 27 72 65 20 74 68 |s why th|ey're th|
|00002af0| 65 72 65 2e 0d 3c 3c 2a | 3e 3e 3d 0d 70 72 6f 63 |ere..<<*|>>=.proc|
|00002b00| 65 64 75 72 65 20 63 68 | 65 63 6b 74 72 65 65 28 |edure ch|ecktree(|
|00002b10| 6e 29 0d 20 20 20 20 6f | 72 69 67 69 6e 61 6c 73 |n). o|riginals|
|00002b20| 20 3a 3d 20 73 65 74 28 | 29 0d 20 20 20 20 65 76 | := set(|). ev|
|00002b30| 65 72 79 20 69 6e 73 65 | 72 74 28 6f 72 69 67 69 |ery inse|rt(origi|
|00002b40| 6e 61 6c 73 2c 20 28 21 | 6e 2e 63 73 2e 61 72 6d |nals, (!|n.cs.arm|
|00002b50| 73 29 2e 6f 72 69 67 69 | 6e 61 6c 29 0d 20 20 20 |s).origi|nal). |
|00002b60| 20 64 65 6c 65 74 65 6d | 61 74 63 68 69 6e 67 28 | deletem|atching(|
|00002b70| 6e 2c 20 6f 72 69 67 69 | 6e 61 6c 73 29 0d 20 20 |n, origi|nals). |
|00002b80| 20 20 65 76 65 72 79 20 | 61 20 3a 3d 20 21 6f 72 | every |a := !or|
|00002b90| 69 67 69 6e 61 6c 73 20 | 64 6f 20 0d 20 20 20 20 |iginals |do . |
|00002ba0| 20 20 20 20 77 61 72 6e | 69 6e 67 28 22 4e 6f 20 | warn|ing("No |
|00002bb0| 77 6f 72 64 20 6d 61 74 | 63 68 65 73 20 70 61 74 |word mat|ches pat|
|00002bc0| 74 65 72 6e 20 61 74 20 | 22 2c 20 69 6d 61 67 65 |tern at |", image|
|00002bd0| 28 61 2e 66 69 6c 65 29 | 2c 20 22 2c 20 6c 69 6e |(a.file)|, ", lin|
|00002be0| 65 20 22 2c 20 61 2e 6c | 69 6e 65 29 0d 20 20 20 |e ", a.l|ine). |
|00002bf0| 20 69 66 20 68 61 73 6e | 6f 6d 61 74 63 68 28 6e | if hasn|omatch(n|
|00002c00| 29 20 74 68 65 6e 0d 20 | 20 20 20 20 20 20 20 77 |) then. | w|
|00002c10| 61 72 6e 69 6e 67 28 22 | 43 61 73 65 20 73 74 61 |arning("|Case sta|
|00002c20| 74 65 6d 65 6e 74 20 61 | 74 20 22 2c 20 69 6d 61 |tement a|t ", ima|
|00002c30| 67 65 28 6e 2e 63 73 2e | 61 72 6d 73 5b 31 5d 2e |ge(n.cs.|arms[1].|
|00002c40| 66 69 6c 65 29 2c 20 22 | 2c 20 6c 69 6e 65 20 22 |file), "|, line "|
|00002c50| 2c 0d 09 09 6e 2e 63 73 | 2e 61 72 6d 73 5b 31 5d |,...n.cs|.arms[1]|
|00002c60| 2e 6c 69 6e 65 20 2d 20 | 31 2c 20 22 20 64 6f 65 |.line - |1, " doe|
|00002c70| 73 6e 27 74 20 63 6f 76 | 65 72 20 61 6c 6c 20 63 |sn't cov|er all c|
|00002c80| 61 73 65 73 22 29 0d 20 | 20 20 20 72 65 74 75 72 |ases"). | retur|
|00002c90| 6e 20 6e 0d 65 6e 64 0d | 0d 70 72 6f 63 65 64 75 |n n.end.|.procedu|
|00002ca0| 72 65 20 64 65 6c 65 74 | 65 6d 61 74 63 68 69 6e |re delet|ematchin|
|00002cb0| 67 28 6e 2c 20 6f 72 69 | 67 69 6e 61 6c 73 29 0d |g(n, ori|ginals).|
|00002cc0| 20 20 20 20 69 66 20 2a | 6f 72 69 67 69 6e 61 6c | if *|original|
|00002cd0| 73 20 3d 20 30 20 74 68 | 65 6e 20 72 65 74 75 72 |s = 0 th|en retur|
|00002ce0| 6e 0d 20 20 20 20 65 6c | 73 65 20 69 66 20 2a 6e |n. el|se if *n|
|00002cf0| 2e 63 68 69 6c 64 72 65 | 6e 20 3e 20 30 20 74 68 |.childre|n > 0 th|
|00002d00| 65 6e 20 65 76 65 72 79 | 20 64 65 6c 65 74 65 6d |en every| deletem|
|00002d10| 61 74 63 68 69 6e 67 28 | 28 21 6e 2e 63 68 69 6c |atching(|(!n.chil|
|00002d20| 64 72 65 6e 29 2e 6e 6f | 64 65 2c 20 6f 72 69 67 |dren).no|de, orig|
|00002d30| 69 6e 61 6c 73 29 0d 20 | 20 20 20 65 6c 73 65 20 |inals). | else |
|00002d40| 65 76 65 72 79 20 64 65 | 6c 65 74 65 28 6f 72 69 |every de|lete(ori|
|00002d50| 67 69 6e 61 6c 73 2c 20 | 28 21 6e 2e 63 73 2e 61 |ginals, |(!n.cs.a|
|00002d60| 72 6d 73 29 2e 6f 72 69 | 67 69 6e 61 6c 29 0d 65 |rms).ori|ginal).e|
|00002d70| 6e 64 0d 0d 70 72 6f 63 | 65 64 75 72 65 20 68 61 |nd..proc|edure ha|
|00002d80| 73 6e 6f 6d 61 74 63 68 | 28 6e 29 0d 20 20 20 20 |snomatch|(n). |
|00002d90| 69 66 20 2a 6e 2e 63 68 | 69 6c 64 72 65 6e 20 3e |if *n.ch|ildren >|
|00002da0| 20 30 20 74 68 65 6e 20 | 72 65 74 75 72 6e 20 68 | 0 then |return h|
|00002db0| 61 73 6e 6f 6d 61 74 63 | 68 28 28 21 6e 2e 63 68 |asnomatc|h((!n.ch|
|00002dc0| 69 6c 64 72 65 6e 29 2e | 6e 6f 64 65 29 0d 20 20 |ildren).|node). |
|00002dd0| 20 20 65 6c 73 65 20 69 | 66 20 2a 6e 2e 63 73 2e | else i|f *n.cs.|
|00002de0| 61 72 6d 73 20 3d 20 30 | 20 74 68 65 6e 20 72 65 |arms = 0| then re|
|00002df0| 74 75 72 6e 20 20 23 20 | 66 6f 75 6e 64 20 69 74 |turn # |found it|
|00002e00| 0d 65 6e 64 0d 40 0d 5c | 73 65 63 74 69 6f 6e 7b |.end.@.\|section{|
|00002e10| 49 6e 64 69 63 65 73 7d | 0d 5c 73 75 62 73 65 63 |Indices}|.\subsec|
|00002e20| 74 69 6f 6e 7b 43 68 75 | 6e 6b 73 7d 0d 5c 6e 6f |tion{Chu|nks}.\no|
|00002e30| 77 65 62 63 68 75 6e 6b | 73 0d 5c 73 75 62 73 65 |webchunk|s.\subse|
|00002e40| 63 74 69 6f 6e 7b 49 64 | 65 6e 74 69 66 69 65 72 |ction{Id|entifier|
|00002e50| 73 7d 0d 5c 6e 6f 77 65 | 62 69 6e 64 65 78 0d |s}.\nowe|bindex. |
+--------+-------------------------+-------------------------+--------+--------+